package Tools

// 获取配置文件
import (
	"os"

	"github.com/Unknwon/goconfig"
)

//初始化环境变量
func InitEnv(env *map[string]interface{}) {
	var app_env = os.Getenv("APP_ENV")
	if app_env != "" {
		(*env)["app_env"] = app_env
	}
	initConf(env)
}

//初始化配置
func initConf(env *map[string]interface{}) {
	var path = ((*env)["config"]).(string) + "/config/" + (*env)["app_env"].(string)
	var configArr = map[string]string{"sys": "sys.ini", "url": "url.ini"}
	for k, v := range configArr {
		_, err := os.Stat(path + "/" + v)
		if err != nil {
			panic(v + " is can not to be find!")
		}
		cfg, err := goconfig.LoadConfigFile(path + "/" + v)
		if err != nil {
			panic("配置文件" + v + "读取失败!")
		}
		(*env)["config_"+k] = cfg
	}
}
